package com.ruoyi.web.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.BaseDto;
import com.ruoyi.common.core.domain.JsonResponse;
import com.ruoyi.system.domain.dto.TAppDto;
import com.ruoyi.system.domain.dto.TAppInterfaceDto;
import com.ruoyi.system.domain.po.TApp;
import com.ruoyi.system.domain.po.TInterface;
import com.ruoyi.system.domain.vo.TAppVo;
import com.ruoyi.system.domain.vo.TInterfaceVo;
import com.ruoyi.system.service.TAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author nanyang
 */
@RestController
@RequestMapping("/app")
@Api(tags = "应用、应用关联管理")
public class TAppController {

    @Resource
    TAppService appService;


    @ApiOperation("新增应用")
    @PostMapping("/insertApp")
    public JsonResponse insertApp(@RequestBody @Validated TAppDto.Insert appInsert){
        return JsonResponse.ok(appService.insertApp(appInsert));
    }

    @ApiOperation("修改应用")
    @PostMapping("/updateApp")
    public JsonResponse updateApp(@RequestBody @Validated TAppDto.Update appUpdate){
        return JsonResponse.ok(appService.updateApp(appUpdate));
    }

    @ApiOperation("删除应用")
    @PostMapping("/deleteApp")
    public JsonResponse deleteApp(@RequestBody @Validated TAppDto.Delete appDelete){
        return JsonResponse.ok(appService.deleteApp(appDelete));
    }

    @ApiOperation("查询应用列表")
    @PostMapping("/listApp")
    public JsonResponse<PageInfo<TAppVo>> listApp(@RequestBody @Validated BaseDto<TAppDto.Query> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(appService.listApp(list.getParam())));
    }

    @ApiOperation("新增应用接口关联")
    @PostMapping("/insertAppInterface")
    public JsonResponse insertAppInterface(@RequestBody @Validated TAppInterfaceDto.Insert appInterfaceInsert){
        return JsonResponse.ok(appService.insertAppInterface(appInterfaceInsert));
    }


    @ApiOperation("删除应用接口关联")
    @PostMapping("/deleteAppInterface")
    public JsonResponse deleteAppInterface(@RequestBody @Validated TAppInterfaceDto.Delete appInterfaceDelete){
        return JsonResponse.ok(appService.deleteAppInterface(appInterfaceDelete));
    }


    @ApiOperation("查询应用对应接口列表")
    @PostMapping("/listAppInterface")
    public JsonResponse<PageInfo<TInterfaceVo>> listAppInterface(@RequestBody @Validated BaseDto<TAppInterfaceDto.Query> list){
        PageHelper.startPage(list.getPageNum(), list.getPageSize(), list.getSort());
        return JsonResponse.ok(new PageInfo<>(appService.listAppInterface(list.getParam())));
    }
    
}
